﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Animals
{
    class Animal
    {
        private string name;
        private string kind;
        public event AnimalNameChangedEventHandler NameChanged;


        public Animal(string name, string kind)
        {
            this.name = name;
            this.kind = kind;
        }

        public string Name
        {
            get
            {
                return name;
            }
            set
            {
                if (value != null) 
                {
                    OnAnimalNameChange(value);
                    name = value;
                }
            }
        }

        public string Kind
        {
            get
            {
                return kind;
            }
            set
            {
                kind = value;
            }
        }

        public static void Animal_NameChanged(object sender, AnimalNameChangedEventArgs args)
        {
            if (args.OldName == args.NewName)
            {
                Console.WriteLine("The new name is the same as the old name!");
            }
            else 
            {
                Console.WriteLine("The name {0} is changed to: {1}",args.OldName,args.NewName);
            }
        }

        public void OnAnimalNameChange(string newName) 
        {
            if (newName == null)
            {
                throw new ArgumentNullException("You can`t change name to null.");
            }
            else if (newName == string.Empty)
            {
                throw new ArgumentOutOfRangeException("You can`t rename your to an empty string.");
            }
            else 
            {
                AnimalNameChangedEventArgs args = new AnimalNameChangedEventArgs(this.Name, newName);
                NameChanged(this, args);
            }
        }
    }
}
